home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / langs / sozo2 / scsrc20.lzh / JAS.LZH / CROSS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-22  |  2.0 KB  |  148 lines

  1.  
  2. /*
  3.  * Copyright (c) 1991 by Sozobon, Limited.
  4.  *
  5.  * Permission is granted to anyone to use this software for any purpose
  6.  * on any computer system, and to redistribute it freely, with the
  7.  * following restrictions:
  8.  * 1) No charge may be made other than reasonable charges for reproduction.
  9.  * 2) Modified versions must be clearly marked as such.
  10.  * 3) The authors are not responsible for any harmful consequences
  11.  *    of using this software, even if they result from defects in it.
  12.  */
  13.  
  14. /*
  15.  * handle possible alignment and byte-order problems in cross environment
  16.  */
  17.  
  18. pcrossw(w, cp)
  19. short w;
  20. char *cp;
  21. {
  22.     union {
  23.         short w;
  24.         char c[2];
  25.     } u;
  26.  
  27.     u.w = w;
  28. #ifdef LITTLE_ENDIAN
  29.     cp[0] = u.c[1];
  30.     cp[1] = u.c[0];
  31. #else
  32.     cp[0] = u.c[0];
  33.     cp[1] = u.c[1];
  34. #endif
  35. }
  36.  
  37. pcrossl(l, cp)
  38. long l;
  39. char *cp;
  40. {
  41.     union {
  42.         long l;
  43.         char c[4];
  44.     } u;
  45.  
  46.     u.l = l;
  47. #ifdef LITTLE_ENDIAN
  48.     cp[0] = u.c[3];
  49.     cp[1] = u.c[2];
  50.     cp[2] = u.c[1];
  51.     cp[3] = u.c[0];
  52. #else
  53.     cp[0] = u.c[0];
  54.     cp[1] = u.c[1];
  55.     cp[2] = u.c[2];
  56.     cp[3] = u.c[3];
  57. #endif
  58. }
  59.  
  60. static char mklowbuf[4];
  61.  
  62. char *
  63. mklowbyte(l)
  64. long l;
  65. {
  66.     mklowbuf[0] = l;
  67.     return mklowbuf;
  68. }
  69.  
  70. char *
  71. mklowshort(l)
  72. long l;
  73. {
  74.     mklowbuf[0] = l>>8;
  75.     mklowbuf[1] = l;
  76.     return mklowbuf;
  77. }
  78.  
  79. char *
  80. mklowlong(l)
  81. long l;
  82. {
  83.     pcrossl(l, mklowbuf);
  84.     return mklowbuf;
  85. }
  86.  
  87. swapw(cp, n)
  88. char *cp;
  89. {
  90. #ifdef LITTLE_ENDIAN
  91.     char t;
  92.  
  93.     while (n--) {
  94.         t = cp[1];
  95.         cp[1] = cp[0];
  96.         cp[0] = t;
  97.         cp += 2;
  98.     }
  99. #endif
  100. }
  101.  
  102. swapl(cp, n)
  103. char *cp;
  104. {
  105. #ifdef LITTLE_ENDIAN
  106.     char t;
  107.  
  108.     while (n--) {
  109.         t = cp[3];
  110.         cp[3] = cp[0];
  111.         cp[0] = t;
  112.  
  113.         t = cp[2];
  114.         cp[2] = cp[1];
  115.         cp[1] = t;
  116.         cp += 4;
  117.     }
  118. #endif
  119. }
  120.  
  121. struct fsym {
  122.     char name[8];
  123.     short flags;
  124.     short value[2];
  125. } tmpsym;
  126.  
  127. struct sym {
  128.     char name[8];
  129.     short flags;
  130.     long value;
  131. };
  132.  
  133. char *
  134. fixsym(sp)
  135. struct sym *sp;
  136. {
  137.     struct fsym *fp;
  138.     int i;
  139.  
  140.     fp = &tmpsym;
  141.     for (i=0; i<8; i++)
  142.         fp->name[i] = sp->name[i];
  143.     pcrossw(sp->flags, &fp->flags);
  144.     pcrossl(sp->value, fp->value);
  145.  
  146.     return (char *)&tmpsym;
  147. }
  148.